<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>10人抽奖系统</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            padding: 20px;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
        }
        h1 {
            color: #333;
        }
        .names-list {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 10px;
            margin: 20px 0;
        }
        .name-item {
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #f9f9f9;
            transition: all 0.3s;
        }
        .name-item.highlight {
            background-color: #4CAF50;
            color: white;
            transform: scale(1.05);
            box-shadow: 0 0 10px rgba(76, 175, 80, 0.7);
        }
        .lottery-result {
            margin: 30px 0;
            font-size: 24px;
            min-height: 30px;
        }
        button {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
            border-radius: 5px;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #45a049;
        }
        button:disabled {
            background-color: #cccccc;
            cursor: not-allowed;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>10人抽奖系统</h1>
        
        <div class="names-list" id="namesList">
            <!-- 名单将由JS动态生成 -->
        </div>
        
        <div class="lottery-result" id="result">
            点击开始抽奖
        </div>
        
        <button id="drawBtn">开始抽奖</button>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 参与抽奖的人员名单
            const participants = [
                "张三", "李四", "王五", "赵六", "钱七",
                "孙八", "周九", "吴十", "郑十一", "陈十二", "梁永寒", "123", "677", "333", "888"
            ];
            
            const namesList = document.getElementById('namesList');
            const result = document.getElementById('result');
            const drawBtn = document.getElementById('drawBtn');
            
            let isDrawing = false;
            let animationInterval;
            let lastHighlighted = -1;
            let animationSpeed = 100; // 初始动画速度(毫秒)
            let speedIncrement = 5; // 速度增量
            let minSpeed = 50; // 最大速度(最小间隔)
            
            // 生成名单
            function generateNamesList() {
                namesList.innerHTML = '';
                participants.forEach((name, index) => {
                    const nameItem = document.createElement('div');
                    nameItem.className = 'name-item';
                    nameItem.id = `name-${index}`;
                    nameItem.textContent = name;
                    namesList.appendChild(nameItem);
                });
            }
            
            // 高亮名字
            function highlightName(index) {
                // 清除上一个高亮
                if (lastHighlighted >= 0) {
                    document.getElementById(`name-${lastHighlighted}`).classList.remove('highlight');
                }
                
                // 高亮当前名字
                document.getElementById(`name-${index}`).classList.add('highlight');
                lastHighlighted = index;
            }
            
            // 生成随机数(0到participants.length-1)
            function generateRandomIndex() {
                return Math.floor(Math.random() * participants.length);
            }
            
            // 开始抽奖动画
            function startDrawAnimation() {
                let currentSpeed = animationSpeed;
                
                animationInterval = setInterval(() => {
                    // 随机选择一个名字高亮
                    const randomIndex = generateRandomIndex();
                    highlightName(randomIndex);
                    
                    // 逐渐增加速度
                    if (currentSpeed > minSpeed) {
                        currentSpeed -= speedIncrement;
                        clearInterval(animationInterval);
                        animationInterval = setInterval(() => {
                            const randomIndex = generateRandomIndex();
                            highlightName(randomIndex);
                        }, currentSpeed);
                    }
                }, currentSpeed);
            }
            
            // 停止抽奖动画并显示结果
            function stopDrawAnimation() {
                clearInterval(animationInterval);
                
                // 最终结果 - 稍微偏向当前高亮的名字
                let finalIndex;
                if (lastHighlighted >= 0 && Math.random() > 0.3) {
                    // 70%概率使用当前高亮的名字或其附近的名字
                    const offset = Math.floor(Math.random() * 3) - 1; // -1, 0, 1
                    finalIndex = (lastHighlighted + offset + participants.length) % participants.length;
                } else {
                    // 30%概率完全随机
                    finalIndex = generateRandomIndex();
                }
                
                // 高亮最终结果
                highlightName(finalIndex);
                
                // 显示结果
                result.textContent = `恭喜 ${participants[finalIndex]} 中奖！`;
            }
            
            // 初始化名单
            generateNamesList();
            
            // 点击抽奖按钮
            drawBtn.addEventListener('click', function() {
                if (isDrawing) {
                    // 停止抽奖
                    stopDrawAnimation();
                    drawBtn.textContent = "再抽一次";
                    isDrawing = false;
                } else {
                    // 开始抽奖
                    result.textContent = "抽奖中...";
                    startDrawAnimation();
                    drawBtn.textContent = "停止抽奖";
                    isDrawing = true;
                }
            });
        });
    </script>
</body>
</html>
    